/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: javase - InputStream1
 * <p>Powered by webrx On 2021-12-15 09:40:41
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class InputStream1 {
    public static void main(String[] args) {
        Map<String, String> t = new HashMap<>();
        t.put("ffd8ffe000104a464946", "jpg");

        String c = "d:/c.jpg";//ffd8ffe000104a464946
        c = "d:/d.tar.gz";//    ffd8ffe000104a464946
        File f = new File(c);
        System.out.println(f.getName());
        System.out.println(f.length());
        byte[] buf = new byte[10];
        try (var is = new FileInputStream(f)) {
            int len = is.read(buf);
            StringBuilder sbu = new StringBuilder();
            for (byte b : buf) {
                sbu.append(String.format("%02x", b));
            }
            System.out.println(sbu);

            System.out.println(t.getOrDefault(sbu.toString(), "未知"));

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
